package one.four.thirty;

import one.three.fortyEight.Deque;

public class DequeAlpha<Item> {

	private Stack<Item> stack;
	private Steque<Item> steque;

	public void pushLeft(Item item) {
		steque.push(item);
	}

	public void pushRight(Item item) {
		steque.enqueue(item);
	}

	public Item popLeft() {
		return steque.pop();
	}

	public Item popRight() {
		if (!stack.isEmpty()) {
			while (!stack.isEmpty()) {
				stack.pop();
			}
		}
		while (!steque.isEmpty()) {
			stack.push(steque.pop());
		}
		Item res = stack.pop();
		while (!stack.isEmpty()) {
			steque.push(stack.pop());
		}

		return res;
	}

	public static void main(String[] args) {
		Deque<String> d = new Deque<String>();
		/*
		 * d.pushRight("a"); d.pushRight("b"); d.pushRight("c");
		 * 
		 * System.out.println(d.popRight()); System.out.println(d.popRight());
		 */
		d.pushLeft("a");
		d.pushLeft("b");
		d.pushLeft("c");

		System.out.println(d.popRight());
		System.out.println(d.popRight());
	}

}
